package com.hong.demo.other.flink;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

public class MapTest {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<Integer> stream = env.fromCollection(Arrays.asList(1, 2, 3));

        // MapFunction<Integer, String>() 输入和输出的类型
        SingleOutputStreamOperator<String> map = stream.map(new MapFunction<Integer, String>() {

            @Override
            public String map(Integer integer) throws Exception {
                return "数字: " + integer;
            }
        });

        map.print();

        env.execute();
    }
}
